const app = getApp()
const $ = app.globalData
Page({
	data: {
		name:'',
		phone:''
	},
	onLoad: function(options) {
		console.log(options)
		var that = this
		var thatid = options.id
		var thatquhuo = options.quhuo?true:false
		wx.request({
			url:$.AdminUrl+"/YApi/order_get",
			data:{orderid:thatid},
			success:function(data){
				that.setData({
					orderid:thatid,
					thatquhuo:data.data.obj.expresstype?true:false,
					orderDetails:data.data.obj
				})
				console.log(data)
			}
		})
	},
	
	// 快递单号
	phoneinput:function(e){
		console.log(e.detail.value)
		this.setData({phone:e.detail.value})
	},
	// 快递公司
	nameinput:function(e){
		this.setData({name:e.detail.value})
	},
	
	// 返回
	fanhui:function(){
		wx.navigateBack()
	},
	// 取货
	goquhuo:function(){
		var that = this
		wx.request({
			url:$.AdminUrl+"/YApi/orderDelivery",
			data:{
				shopid:$.myshopid,
				orderid:that.data.orderid
			},
			success:function(res){
				if(res.data.code){
					wx.showToast({
					    title: res.data.msg,
					    duration: 3000
					})
					$.onshow = true
				}else{
					wx.showToast({
						icon:"none",
					    title: res.data.msg,
					    duration: 3000
					})
				}
			}
		})
		
		// wx.scanCode({
		// 	success: (res) => {
		// 		console.log(res)
		// 		var ordernub = JSON.parse(res.result).ordernum
		// 		wx.request({
		// 			url: $.AdminUrl + "/YApi/getOrderByOrdernum",
		// 			data: {
		// 				ordernum: ordernub
		// 			},
		// 			success: function(data) {
		// 				console.log(data)
		// 			}
		// 		})
		// 	},
		// 	fail: (res) => {
		// 		console.log(res);
		// 	}
		// })
		// return false;
	},
	// 发货
	gotologin:function(){
		var that = this
		if(that.data.phone == ''){
			wx.showToast({
				icon:"none",
			    title: '请输入快递单号',
			    duration:3000
			})
		}else if(that.data.name == ''){
			wx.showToast({
				icon:"none",
			    title: '请输入快递公司名称',
			    duration: 3000
			})
		}else{
			wx.request({
				url:$.AdminUrl+"/YApi/orderDelivery",
				data:{
					shopid:$.myshopid,
					orderid:that.data.orderid,
					expressname:that.data.name,
					expressnum:that.data.phone
				},
				success:function(res){
					if(res.data.code){
						wx.showToast({
						    title: res.data.msg,
						    duration: 3000
						})
						$.onshow = true
						setTimeout(function(){
							wx.navigateBack()
						},3000)
					}else{
						wx.showToast({
							icon:"none",
						    title: res.data.msg,
						    duration: 3000
						})
					}
					console.log(res)
				}
			})
		}
		return false;
	}
	
});
